package com.ruoyi.product.service.impl;

import java.util.List;

import com.ruoyi.product.domain.vo.CommentHf;
import com.ruoyi.product.domain.vo.ProductXX;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.product.mapper.ProductCommentsMapper;
import com.ruoyi.product.domain.ProductComments;
import com.ruoyi.product.service.IProductCommentsService;

/**
 * 评价表Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-07-29
 */
@Service
public class ProductCommentsServiceImpl implements IProductCommentsService 
{
    @Autowired
    private ProductCommentsMapper productCommentsMapper;

    /**
     * 查询评价表
     * 
     * @param id 评价表主键
     * @return 评价表
     */
    @Override
    public ProductComments selectProductCommentsById(Long id)
    {
        return productCommentsMapper.selectProductCommentsById(id);
    }

    /**
     * 查询评价表列表
     * 
     * @param productComments 评价表
     * @return 评价表
     */
    @Override
    public List<ProductComments> selectProductCommentsList(ProductComments productComments)
    {
        return productCommentsMapper.selectProductCommentsList(productComments);
    }

    /**
     * 新增评价表
     * 
     * @param productComments 评价表
     * @return 结果
     */
    @Override
    public int insertProductComments(ProductComments productComments)
    {
        return productCommentsMapper.insertProductComments(productComments);
    }

    /**
     * 修改评价表
     * 
     * @param productComments 评价表
     * @return 结果
     */
    @Override
    public int updateProductComments(ProductComments productComments)
    {
        CommentHf commentHf = new CommentHf();
        String hf = productComments.getHf();
        commentHf.setHf(hf);
        Long id = productComments.getId();
        commentHf.setPid(productComments.getId());
        CommentHf commentHf1=productCommentsMapper.selectComment(productComments.getHfnr());
        if (commentHf1!=null){
            String hf1 = commentHf1.getHf();
            hf1=hf1+"/"+hf;
            commentHf.setHf(hf1);
            return productCommentsMapper.updateComment(commentHf);
        }
        productCommentsMapper.updateCommentsProduct(id);
        return productCommentsMapper.updateProductComments(commentHf);
    }

    /**
     * 批量删除评价表
     * 
     * @param ids 需要删除的评价表主键
     * @return 结果
     */
    @Override
    public int deleteProductCommentsByIds(Long[] ids)
    {
        return productCommentsMapper.deleteProductCommentsByIds(ids);
    }

    /**
     * 删除评价表信息
     * 
     * @param id 评价表主键
     * @return 结果
     */
    @Override
    public int deleteProductCommentsById(Long id)
    {
        return productCommentsMapper.deleteProductCommentsById(id);
    }

    @Override
    public List<ProductXX> selectProductList() {
        return productCommentsMapper.selectProductList();
    }
}
